| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | describe('Model Generator', function () { |
||
| 41 | describe('Model Validations', function() { |
||
| 42 | it('Presence Failed', function() { |
||
| 43 | var p = Ext.create('Test.model.Person'); |
||
| 44 | p.set("firstName", ""); |
||
| 45 | var errors = p.validate(); |
||
| 46 | expect(errors.getByField("firstName").length).toBe(1); |
||
| 47 | }); |
||
| 48 | it('Presence Success', function() { |
||
| 49 | var p = Ext.create('Test.model.Person'); |
||
| 50 | p.set("lastName", "test"); |
||
| 51 | var errors = p.validate(); |
||
| 52 | expect(errors.getByField("lastName").length).toBe(0); |
||
| 53 | }); |
||
| 54 | it('Length Failed', function() { |
||
| 55 | var p = Ext.create('Test.model.Person'); |
||
| 56 | p.set("email", "[email protected]"); |
||
| 57 | var errors = p.validate(); |
||
| 58 | expect(errors.getByField("email").length).toBe(1); |
||
| 59 | p.set("email", "[email protected]"); |
||
| 60 | errors = p.validate(); |
||
| 61 | expect(errors.getByField("email").length).toBe(1); |
||
| 62 | }); |
||
| 63 | it('Length Success', function() { |
||
| 64 | var p = Ext.create('Test.model.Person'); |
||
| 65 | p.set("email", "[email protected]"); |
||
| 66 | var errors = p.validate(); |
||
| 67 | expect(errors.getByField("email").length).toBe(0); |
||
| 68 | }); |
||
| 69 | it('Email Failed', function() { |
||
| 70 | var p = Ext.create('Test.model.Person'); |
||
| 71 | p.set("email", "as.ad.coma1.au"); |
||
| 72 | var errors = p.validate(); |
||
| 73 | expect(errors.getByField("email").length).toBe(1); |
||
| 74 | }); |
||
| 75 | it('Email Success', function() { |
||
| 76 | var p = Ext.create('Test.model.Person'); |
||
| 77 | p.set("email", "[email protected]"); |
||
| 78 | var errors = p.validate(); |
||
| 79 | expect(errors.getByField("email").length).toBe(0); |
||
| 80 | }); |
||
| 81 | it('Regex Success', function() { |
||
| 82 | var p = Ext.create('Test.model.Person'); |
||
| 83 | p.set("regex", "81 4"); |
||
| 84 | var errors = p.validate(); |
||
| 85 | expect(errors.getByField("regex").length).toBe(0); |
||
| 86 | }); |
||
| 87 | it('Regex Failed', function() { |
||
| 88 | var p = Ext.create('Test.model.Person'); |
||
| 89 | p.set("regex", "a1 4"); |
||
| 90 | var errors = p.validate(); |
||
| 91 | expect(errors.getByField("regex").length).toBe(1); |
||
| 92 | }); |
||
| 93 | it('Choice Success', function() { |
||
| 94 | var p = Ext.create('Test.model.Person'); |
||
| 95 | p.set("color", "red"); |
||
| 96 | var errors = p.validate(); |
||
| 97 | expect(errors.getByField("color").length).toBe(0); |
||
| 98 | }); |
||
| 99 | it('Choice Failed', function() { |
||
| 100 | var p = Ext.create('Test.model.Person'); |
||
| 101 | p.set("color", "green"); |
||
| 102 | var errors = p.validate(); |
||
| 103 | expect(errors.getByField("color").length).toBe(1); |
||
| 104 | }); |
||
| 105 | }); |
||
| 106 | describe('Model Associations', function() { |
||
| 129 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.